{include file="header/index" /}
<meta charset="UTF-8">
		<!--导航end-->

		<div class="container bgwhite relative">
			<h2 class="container-title">用户信息</h2>
			<div class="col-xs-12 mt20 userInfor">
				<form class="form-horizontal" name="userAdd" id="userAdd" method="post" action="" enctype="multipart/form-data">
					<table class="row table table-bordered">  
						<tbody>
							<tr>
								<td class="col-xs-12" colspan="2">基本信息</td>
							</tr>
							<input name="id" value="{$data.id}" type="hidden"/>
							<tr>
								<td class="col-xs-2 t_right bgf6" style="line-height: 111px;">用户头像</td>
								<td class="col-xs-10">
									<p class="userImg t_left">
										{notempty  name="$data['avatar_img']"}
											<span class="userImg-tu"><img id="img_data" src="{:Config('IMAGES_PATH')}{$data.avatar_img}"></span>
										{else /}
											<span class="userImg-tu"><img id="img_data" src="__IMG__/userImg.jpg"></span>
										{/notempty}
										<span class="clearfix userImg-btn" ><input class="fl" type="file"   onchange="qwe()" value="" id="avatar_img" name="avatar_img" >（建议尺寸 100x100）</span>
									</p>
								</td>
							</tr>
							<tr>
								<td class="col-xs-2 t_right bgf6">用户名</td>
								<td class="col-xs-10 t_left">
									<input class="userInput" type="text" value="{$data.account}"  readonly="readonly">
								</td>
							</tr>
							<tr>
								<td class="col-xs-2 t_right bgf6">密码</td>
								<td class="col-xs-10 t_left">
									<p class="userModifyBtn" onclick="modify()">修改密码</p>
									<div class="user_modify_password">
										<p>
											<label>原密码</label>
											<input type="password" name="old_password" value=""/>
										</p>
										<p>
											<label>新密码</label>
											<input type="password" name="new_password" value=""/>
										</p>
										<p>
											<label>确认密码</label>
											<input type="password" name="password" value=""/>
										</p>
									</div>

								</td>
							</tr>
							<tr>
								<td class="col-xs-2 t_right bgf6">用户类型</td>
								<td class="col-xs-10 t_left">
									{if condition="$is_admin eq 1"}
										<input class="userInput" type="text" value="超级管理员"  readonly="readonly">
									{else /}
										<input class="userInput" type="text" value="管理员"  readonly="readonly">
									{/if}
								
									
								</td>
							</tr>
							<!-- <tr>
								<td class="col-xs-2 t_right bgf6">所属区域</td>
								<td class="col-xs-10 t_left">
									<input class="userInput" type="text" value="" name="">
								</td>
							</tr> -->
							<tr>
								<td class="col-xs-2 t_right bgf6">姓名</td>
								<td class="col-xs-10 t_left">
									<input class="userInput"  type="text" value="{$data.name}" name="name">
								</td>
							</tr>
							<tr>
								<td class="col-xs-2 t_right bgf6">邮箱</td>
								<td class="col-xs-10 t_left">
									<input class="userInput" id="email" type="text" value="{$data.email}" name="email">
								</td>
							</tr>
							<tr>
								<td class="col-xs-2 t_right bgf6">电话</td>
								<td class="col-xs-10 t_left">
									<input class="userInput" type="text" value="{$data.phone}" name="phone">
								</td>
							</tr>
							<tr>
								<td class="col-xs-2 t_right bgf6">账号状态</td>
								<td class="col-xs-10 t_left">
									{if condition="$data['status'] eq 1"}
										<input class="userInput" type="text" value="正常"  readonly="readonly">
									{else /}
										<input class="userInput" type="text" value="冻结"  readonly="readonly">
									{/if}
								</td>
							</tr>
							<tr>
								<td class="col-xs-2 t_right bgf6">联系地址</td>
								<td class="col-xs-10 t_left">
									<p class="userTxt">
										<textarea maxlength="100" name="address" id="address">{$data.address}</textarea>
										<span>100以内</span>
									</p>
									
								</td>
							</tr>

						</tbody>
					</table>
					<p class="letters-btn">
						<button type="button" class="lettersSend-btn" onclick="addUser()">提交</button>
						<button type="button" class="lettersCancel-btn" onclick="letterHides()">取消</button>
					</p>
				</form>
			</div>

		</div>
		<script>
			function modify(){
				$(".user_modify_password").toggle()
			}
			
			
			
			
			/**
			 * ajax 表单提交
			 */
			function addUser(){
				if($.trim($("input[name='name']").val())==''){
					layer.msg('请填写管理员真实姓名', {icon: 2,time: 2000});
					return false;
				}
				if($.trim($("input[name='phone']").val())==''){
					layer.msg('请填写管理员手机号', {icon: 2,time: 2000});
					return false;
				}
				if($.trim($("input[name='email']").val())==''){
					layer.msg('请填写管理员邮箱', {icon: 2,time: 2000});
					return false;
				}
				if($.trim($("#address").text())==''){
					layer.msg('请填写管理员地址', {icon: 2,time: 2000});
					return false;
				}
				if (!$("#email").val().match(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)) { 
					layer.msg('邮箱格式不正确', {icon: 2,time: 2000});
					return false;
				} 
				if(!(/^1[34578]\d{9}$/.test($.trim($("input[name='phone']").val())))){ 
					layer.msg('手机号码格式不正确', {icon: 2,time: 2000});
					return false; 
				} 
				
				var old_password = $.trim($("input[name='old_password']").val());
				var new_password = $.trim($("input[name='new_password']").val());
				var password = $.trim($("input[name='new_password']").val());
				
				if(old_password || new_password || password){
					if(old_password == ''){
						layer.msg('原密码不能为空', {icon: 2,time: 2000});
						return false;
					}
					if(new_password != password){
						layer.msg('两次密码输入不匹配', {icon: 2,time: 2000});
						return false;
					}
				}
				 
				
				
				
				var formData = new FormData($( "#userAdd" )[0]); 
				
			     $.ajax({    
			          url:  "{:url('Users/PersonalInformation')}",  /*这是处理文件上传的servlet*/  
			          type: 'POST',    
			          data: formData,    
			          async: false,    
			          cache: false,    
			          contentType: false,    
			          processData: false,
			          dataType : 'json',
			          success: function (returndata) {
			        	 if(returndata.code == '1'){
			        		 layer.msg(returndata.msg, {icon: 1,time: 2000},function(){window.location.href=window.location.href});
			        	 }else{
			        		 layer.msg(returndata.msg, {icon: 2,time: 2000}); 
			        	 }
			              
			          },error: function (returndata) {    
						layer.msg('数据异常', {icon: 2,time: 2000});
						return false; 
			          }    
			     });  
			}

			
			
			
			/**
			 * 图片显示
			 */

			function qwe() {
				var file = document.getElementById("avatar_img").files[0];
				var reader = new FileReader();
				reader.onload = function(e) {
					img_data.src = this.result;
				};
				reader.readAsDataURL(file); //Base64
			  }
			
			
			
		</script>
	</body>

</html>